// Learn TypeScript:
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import { _decorator, Component, Node,Label,tween} from 'cc';
import {GameMain} from "./GameMain";
import Platform from "./Platform";
import {NativeEvt} from "./GameConfig";

const {ccclass, property} = _decorator;

//用户协议UI
@ccclass
export default class AgreementUI extends Component {

    @property({type:Node})
    xieyiUI: Node= null;

    @property({type:Node})
    yinsiUI:Node=null;

    @property({type:Label})
    refuseLabel:Label=null;

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start () {

    }

    public onXieyiBtnClicked()
    {
        this.xieyiUI.active=true;
    }

    public onYinsiBtnClicked()
    {
        this.yinsiUI.active=true;
    }

    public showYinsiUI()
    {
        this.yinsiUI.active=true;
    }

    public closeXieyiUI()
    {
        this.xieyiUI.active=false;
    }

    public closeYinsiUI()
    {
        this.yinsiUI.active=false;
    }

    public onRefuseClicked()
    {
        if(this.refuseLabel.node.active)
            return;
        this.refuseLabel.node.active=true;
        this.refuseLabel.node.opacity=255;
        //fade out
        this.scheduleOnce(()=>{
            tween(this.refuseLabel.node).to(1, { opacity: 0}).call(()=>{
                this.refuseLabel.node.opacity=255;
                this.refuseLabel.node.active=false;
            }).start();
        },1.5);
    }

    public onAgreeClicked()
    {
        this.close();
        //save data
        GameMain.instance.gameData.updateAgreed(true);

        if(Platform.isAndroid())
        {
            //通知原生平台
            GameMain.instance.sendNativeEvent(NativeEvt.PrivacyPass);
        }
    }

    public show()
    {
        this.node.active=true;
    }

    public close()
    {
        this.node.active=false;
    }
    // update (dt) {}
}
